package 回溯算法;

import java.util.ArrayList;
import java.util.List;

public class 电话号码的字母组合 {
    static class Solution {
        List<String> list = new ArrayList<>();

        public List<String> letterCombinations(String digits) {
            if (digits == null || digits.length() == 0) {
                return list;
            }
            String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
            backTracking(digits, numString, 0);
            return list;

        }

        StringBuilder temp = new StringBuilder();
        public void backTracking(String digits,String[] numString,int num){
            if (num == digits.length()){
                list.add(temp.toString());
                return;
            }
            String str = numString[digits.charAt(num) - '0'];
            for (int i = 0; i < str.length(); i++) {
                temp.append(str.charAt(i));
                backTracking(digits,numString,num+1);
                //回溯
                temp.deleteCharAt(digits.length()-1);
            }
        }

    }
}
